﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using System.Data;
using Tools;
using Tour.DAL;

namespace Tour.BLL
{
    /// <summary>
    /// Summary description for Per_ActionsRoles
    /// </summary>
    public class TblConfigManager : TblConfigManagerBase
    {
        public TblConfigManager()
        {
            //
            // TODO: Add constructor logic here
            //
        }
        public static TblConfigManager CreateInstant()
        {
            return new TblConfigManager();
        }
        public List<TblConfigEntity> SelectConfigBy(int? Id, string TextId, int? PageSize, int? PageIndex, out int TotalRow, string OrderByEx, string Collate)
        {
            TotalRow = 0;
            List<TblConfigEntity> lsresult = new List<TblConfigEntity>();
            List<SqlParameter> ls = new List<SqlParameter>();
            SqlParameter sp = new SqlParameter("@TotalRow", TotalRow);
            sp.Direction = System.Data.ParameterDirection.Output;
            ls.Add(sp);
            if (Id.HasValue)
                ls.Add(new SqlParameter("@Id", Id.Value));
            if (TextId != "")
                ls.Add(new SqlParameter("@TextID", TextId));
            if (PageSize.HasValue && PageIndex.HasValue)
            {
                ls.Add(new SqlParameter("@PageSize", PageSize.Value));
                ls.Add(new SqlParameter("@PageIndex", PageIndex.Value));
            }
            if (!OrderByEx.Equals(string.Empty) && !Collate.Equals(string.Empty))
            {
                ls.Add(new SqlParameter("@OrderByEx", OrderByEx));
                ls.Add(new SqlParameter("@Collate", Collate));
            }
            SqlParameter[] sqlparam = ls.ToArray();
            DataTable dt = SqlHelper.ExecuteDataTable(SqlHelper.TourConnectString, CommandType.StoredProcedure, "tr_SelectTblConfigBy", sqlparam);
            TotalRow = int.Parse(sqlparam[0].Value.ToString());
            if (dt != null && dt.Rows.Count > 0)
                for (int i = 0; i < dt.Rows.Count; i++)
                    lsresult.Add(GetTblConfigEntity(dt.Rows[i]));
            return lsresult;
        }
        public List<TblConfigEntity> SelectConfigBy(int? Id, string TextId, string OrderByEx, string Collate)
        {
            int TotalRow = 0;
            return SelectConfigBy(Id, null, null, null, out TotalRow, OrderByEx, Collate);
        }
        public List<TblConfigEntity> SelectConfigOneBy(int? Id, string TextId, string OrderByEx, string Collate)
        {
            int TotalRow = 0;
            return SelectConfigBy(Id, TextId, 1, 1, out TotalRow, OrderByEx, Collate);
        }
        //public void SortConfigBy(int ParentId)
        //{
        //    List<SqlParameter> ls = new List<SqlParameter>();
        //    //ls.Add(new SqlParameter("@TourId", ParentId));
        //    SqlParameter[] sqlparam = ls.ToArray();
        //    SqlHelper.ExecuteNonQuery(SqlHelper.TourConnectString, CommandType.StoredProcedure, "tr_SortTblConfig", sqlparam);
        //}
    }
}
